# import base64,json,time
# import hashlib
#
# header_data = {"typ":"jwt","alg":"HS256"}
# print(type(header_data))
# # 转换成json格式的字符串
# jo = json.dumps(header_data)
# print(type(jo))
# print(jo)
# # 将字符串转换成字节形式
# jo_encode = jo.encode()
# print(jo_encode)
# # 将字节数据进行base64编码
# bs = base64.b64encode(jo_encode)
# print(bs)
#
# jwt_hd = bs.decode()
# print(jwt_hd)
import json

# header = base64.b64encode(json.dumps(header_data).encode()).decode()
# print(header)

# # 当前时间
# current_time = time.time()
#
# payload_data = {
#     "sub":"root",
#     "exp":current_time+(60*60),
#     "nbf":current_time,
#     "name":"root",
#     "user_id":1,
#     "mobile":"18000000000"
# }
# base64转码后的结果
# cookie  前面的cookie  sindcookie
# 需要字节类型数据（python没有字节数据类型）   字典转成字符串：json，把字符串转成字节，字节转换成字符串
# payloads = base64.b64encode(json.dumps(payload_data).encode()).decode()
# print(payloads)

# 生成签证部分
# 密钥：django项目中的settings中寻找密钥
# 密钥不能泄露
# SECRET_KEY = 'django-insecure-b@w^z!@aora-%2d#eg5)#7k#g!!rp5s4py=oz=rnlhjud!t0w6'
#
# data = header+payloads+SECRET_KEY
# # 获取加密对象，ha256
# HS256 = hashlib.sha256()
#
# HS256.update(data.encode('utf-8'))
#
# signatrue = HS256.hexdigest()
# print(signatrue)

# 手动签发token,jwt生成
# 导入django运行环境
# import os
# import django
# os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'fuguangeduapi.settings.dev')
# django.setup()
#
# from users.models import UsersModel
# from rest_framework_simplejwt.tokens import RefreshToken
#
# try:
#     # 模拟获取登录用户
#     user = UsersModel.objects.get(id=2)
#     # 根据用户，获取刷新token实例
#     refresh = RefreshToken.for_user(user)
#     print(refresh)
#     refresh_token = str(refresh)
#     access_token = refresh.access_token
#     print('...........')
#     print(access_token)
# except UsersModel.DoesNotExist:
#     print('用户不存在，签发失败')
# 容联云短信验证码测试
# from ronglian_sms_sdk import SmsSDK
# import json
# accId = '2c94811c9035ff9f01910ccb7f842cda'
# accToken = 'babfe333fd3c4d7b976e7237fe69e072'
# appId = '2c94811c9035ff9f01910ccb81052ce1'
#
# def send_message():
#     sdk = SmsSDK(accId, accToken, appId)
#     tid = 1
#     mobile = '15137842408'
#     datas = ('0066', '2')
#     resp = sdk.sendMessage(tid, mobile, datas)
#     print(resp)
#     print('------')
#     jrs = json.loads(resp)
#     print(jrs)
#     print('=======')
#     send_type = jrs.get('statusCode')
#     print(send_type)
# send_message()

import oss2,uuid
#打开oss管理控制台，点击概览，下方有access_key
OSS_ACCESS_KEY_ID = "LTAI5tQm1TPX91ExQmjowv4x"
#打开oss管理控制台，点击概览，下方有access_key,创建获取
OSS_ACCESS_KEY_SECRET = "ByciKbQsG9y2tiRM1NHXG2bkpAfySR"
# 名
OSS_BUCKET_NAME = "fuguangedu"

OSS_ENDPOINT = "oss-cn-beijing.aliyuncs.com"
# 拼接服务访问地址
OSS_SERVER_URL = f"https://{OSS_BUCKET_NAME}.{OSS_ENDPOINT}"

# 获取阿里云认证对象
auth  =  oss2.Auth(OSS_ACCESS_KEY_ID,OSS_ACCESS_KEY_SECRET)
# 获取bucket对象，oss操作：上传、下载.....
bucket = oss2.Bucket(auth,OSS_ENDPOINT,OSS_BUCKET_NAME)

# 获取一个文件,使用oss上传选择的文件
# 文件名
IMAGE_NAME = f"demo/{str(uuid.uuid4())}.jpg"
with open('C:\\Users\\11837\\Desktop\\22.jpg', 'rb') as f:

    result = bucket.put_object(IMAGE_NAME, f.read())
    # 打印返回结果
    print(result)
    print(result.status)
    # 打印拼接地址
    print(f"{OSS_SERVER_URL}/{IMAGE_NAME}")













